<?php

namespace app\controller;

use think\facade\Request;
use app\BaseController;
use app\ResourceModel;
use app\controller\ResourceController;

class ResourceOrderController extends ResourceController
{


    public function index()
    {
        $table = $this->param['table'];
        $tableInfo = getTableHeader($table);
        $whereMust = empty($tableInfo[2]) ? [] : $tableInfo[2];
        $searchMust = [];
        if(!empty($tableInfo[3])) {
            foreach ($tableInfo[3] as $key=>$value) {
                if(!empty($this->param[$value[1]])){
                    $searchMust[] = array($key,$value[0],$this->param[$value[1]]);
                }
            }
        }
        $list = $this->model->table($table)->
        alias('o')->where($whereMust)->where($searchMust)->
        field($tableInfo[1])->
        leftJoin('lyx_combo c','o.combo_id=c.id')->leftJoin('lyx_user u','u.id=o.user_id')->
            order(['o.id'=>'desc'])->
            withAttr('pay_time', function($value, $data) {
                return toDate(strtotime($value));
            })->
        paginate($this->pageSize, false, [])->toArray();
        $list['header'] = $tableInfo[0];
        return $this->returnPageJson(1001, '返回数据成功', $list);
    }

}
